/**
 * Candidate number: 35834
 */
package tv.starfu.sequencer;

import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.builder.ImageBuilder;
import de.lessvoid.nifty.builder.LayerBuilder;
import de.lessvoid.nifty.builder.PanelBuilder;
import de.lessvoid.nifty.builder.ScreenBuilder;
import de.lessvoid.nifty.controls.button.builder.ButtonBuilder;
import de.lessvoid.nifty.examples.controls.common.CommonBuilders;
import de.lessvoid.nifty.screen.Screen;
//import net.beadsproject.beads.play.Pattern;
import tv.starfu.sequencer.gui.PatternStepButtonDefinition;

public class Trillian {
 
    private static Screen screen;
    private static CommonBuilders builders = new CommonBuilders();
    //private static Pattern testPattern;
    
    public Trillian(Nifty nifty) {
        createScreen(nifty);
        nifty.gotoScreen("start");
        PatternStepButtonDefinition.register(nifty);
        nifty.loadStyleFile("nifty-default-styles.xml");
        nifty.loadControlFile("nifty-default-controls.xml");
    }
    
    public void display(Nifty nifty) {
              createScreen(nifty);
        nifty.gotoScreen("start");
    }
    
    
    
    private void pauseProcessing() {
 
    }
    
    private Screen createScreen(final Nifty nifty) {
        /* Initial Screen */
        // Must have a uniqueID
        screen = new ScreenBuilder("start") {{
            
            /* Provide ScreenController to handle events 
             * Maybe it can also call data / query model? */
            controller(new TrillianScreenController() {

            });
                /* Background Layer */
                layer(new LayerBuilder("trillian_background") {
                    { childLayoutCenter();
                      backgroundImage("Interface/astrosky.jpg");
                    
                
                /* Container panel */
                panel(new PanelBuilder("trillian_container") {
                    { childLayoutVertical();
                      alignCenter();
                      width("100%");
                      height("80%");
                      backgroundColor("#ecf8");
                             
                      /* Header Panel */
                     panel(new PanelBuilder("trillian_header") {{
                            valignTop();
                            height("20%");
                            backgroundColor("#44f8");
                        }});    // End trillian header
                     
                      /* Splash Panel */
                     panel(new PanelBuilder("trillian_splash") {{
                           // valignTop();
                            height("20%");
                            backgroundColor("#c4f8");
                            childLayoutCenter();

                        }});    // End trillian splash

                     /* Main panel */
                     panel(new PanelBuilder("trillian_main") {{
                            backgroundColor("#44f5");
                            childLayoutCenter();
                            
                            /* Buttons */
                            panel(new PanelBuilder("trillian_activation_grid_buttons") {{
                                childLayoutVertical();
                                valignBottom();
                                width("100%");
                                height("100%");
                                
                                
                                /* First Channel */
                                panel(new PanelBuilder("channel_1") {{
                                    childLayoutHorizontal();
                                    width("100%");
 
                                    padding("10px");
                                    
                                        for(int i = 0; i < 16; ++i) {
                                            
                                              /* ControlID in the format [psb_0_0] */
                                              String controlID = "psb_" + 1 + "_" + i;
                                              String step = "";
                                              String channel = "1";
                                              step = Integer.toString(i);
                                              control(PatternStepButtonDefinition.getControlBuilder
                                                      (controlID, step, channel, "fresh")) ;
                                              interactOnMouseOver("callMe()");
                                        }      
                                }}); // End channel

                                
                                /* Second Channel */
                                panel(builders.hspacer("80px"));
                                panel(new PanelBuilder("channel_2") {{
                                    childLayoutHorizontal();
                                    width("100%");
                                    //height("20%");
                                    padding("10px");
                                    
                                        for(int i = 0; i < 16; ++i) {
                                            
                                              /* ControlID in the format [psb_0_0] */
                                              String controlID = "psb_" + 2 + "_" + i;
                                              String step = "";
                                              String channel = "2";
                                              step = Integer.toString(i);
                                              control(PatternStepButtonDefinition.getControlBuilder
                                                      (controlID, step, channel, "fresh")) ; }      
                                }}); // End channel

                                
                                /* Third Channel */
                                panel(builders.hspacer("80px"));
                                panel(new PanelBuilder("channel_3") {{
                                    childLayoutHorizontal();
                                    width("100%");
                                   // height("20%");
                                    padding("10px");
                                    
                                        for(int i = 0; i < 16; ++i) {
                                            
                                              /* ControlID in the format [psb_0_0] */
                                              String controlID = "psb_" + 3 + "_" + i;
                                              String step = "";
                                              String channel = "3";
                                              step = Integer.toString(i);
                                              control(PatternStepButtonDefinition.getControlBuilder
                                                      (controlID, step, channel, "fresh")) ; }      
                                }}); // End channel

                                
                                /* Fourth Channel */
                                panel(builders.hspacer("100px"));
                                panel(new PanelBuilder("channel_4") {{
                                    childLayoutHorizontal();
                                    width("100%");
                                    height("20%");
                                    padding("10px");
                                    
                                        for(int i = 0; i < 16; ++i) {
                                            
                                              /* ControlID in the format [psb_0_0] */
                                              String controlID = "psb_" + 4 + "_" + i;
                                              String step = "";
                                              String channel = "4";
                                              step = Integer.toString(i);
                                              control(PatternStepButtonDefinition.getControlBuilder
                                                      (controlID, step, channel, "fresh")) ; }      
                                }}); // End channel

                                
                                /* Fifth Channel */
                                panel(builders.hspacer("100px"));
                                panel(new PanelBuilder("channel_5") {{
                                    childLayoutHorizontal();
                                    width("100%");
                                    height("20%");
                                    padding("10px");
                                    
                                        for(int i = 0; i < 16; ++i) {
                                            
                                              /* ControlID in the format [psb_0_0] */
                                              String controlID = "psb_" + 5 + "_" + i;
                                              String step = "";
                                              String channel = "5";
                                              step = Integer.toString(i);
                                              control(PatternStepButtonDefinition.getControlBuilder
                                                      (controlID, step, channel, "fresh")) ; }      
                                }}); // End channel

                                
                                /* Sixth Channel */
                                panel(builders.hspacer("100px"));
                                panel(new PanelBuilder("channel_6") {{
                                    childLayoutHorizontal();
                                    width("100%");
                                    height("20%");
                                    padding("10px");
                                    
                                        for(int i = 0; i < 16; ++i) {
                                            
                                              /* ControlID in the format [psb_0_0] */
                                              String controlID = "psb_" + 6 + "_" + i;
                                              String step = "";
                                              String channel = "6";
                                              step = Integer.toString(i);
                                              control(PatternStepButtonDefinition.getControlBuilder
                                                      (controlID, step, channel, "fresh")) ; }      
                                }}); // End channel

                                
                                /* Seventh Channel */
                                panel(builders.hspacer("100px"));
                                panel(new PanelBuilder("channel_7") {{
                                    childLayoutHorizontal();
                                    width("100%");
                                    height("20%");
                                    padding("10px");
                                    
                                        for(int i = 0; i < 16; ++i) {
                                            
                                              /* ControlID in the format [psb_0_0] */
                                              String controlID = "psb_" + 7 + "_" + i;
                                              String step = "";
                                              String channel = "7";
                                              step = Integer.toString(i);
                                              control(PatternStepButtonDefinition.getControlBuilder
                                                      (controlID, step, channel, "fresh")) ; }      
                                }}); // End channel
                                
                                // Create button ID as String
                                //control(ControlDefinition.getControlBuilder(String xPos, String yPos)
                                panel(builders.hspacer("10px"));
                        
                            }});     // End trillian activation grid buttons
                            
                        }});        // End trillian main
                     
                     
                }});    // End container panel
            }});        // End layer         
        }}.build(nifty);
        return screen;
    }
}
